package columns

import (
	"fmt"

	"github.com/pkg/errors"

	"github.com/gin-gonic/gin"
	"gogs.xiaoyuanjijiehao.com/antlinker/antcms/app/ginsrv/api/base"
	"gogs.xiaoyuanjijiehao.com/antlinker/antcms/core"
	"gogs.xiaoyuanjijiehao.com/antlinker/antcms/core/columnd"
	"gogs.xiaoyuanjijiehao.com/antlinker/antcms/core/common"
	"gogs.xiaoyuanjijiehao.com/antlinker/antcms/ddd/ginhook"
)

func createColumnCtrl(d core.CmsDomain) *columnCtrl {
	return &columnCtrl{
		BaseContrl: base.BaseContrl{
			Domain: d,
		},
		column: d.Column(),
		car:    d.Column().ColumnAggregateRoot(),
	}
}

// ReqColumnAdd 新增栏目请求
type ReqColumnAdd struct {
	Name      string   `json:"name,omitempty" binding:"required,max=30"`
	ShortName string   `json:"short_name,omitempty" binding:"required,max=10"`
	Kind      int      `json:"kind"`
	Icon      []string `json:"icon,omitempty"`
	Banner    string   `json:"banner,omitempty"`
	Page      string   `json:"page,omitempty"`
	Desc      string   `json:"desc,omitempty" binding:"max=500"`
	ParentID  string   `json:"parent_id,omitempty" binding:"max=40"`
	Org       string   `json:"org,omitempty" binding:"max=40"`
	Owner     string   `binding:"omitempty"`
}
type columnCtrl struct {
	base.BaseContrl
	column columnd.ColumnDomain
	car    columnd.ColumnAggregateRoot
}

func (c columnCtrl) add(ctx *gin.Context) {
	var req ReqColumnAdd

	if err := ctx.BindJSON(&req); err != nil {
		c.ErrBadRequestByBind(ctx, 1, err)
		return
	}
	dctx := c.DDDContext(ctx)
	desc := columnd.ColumnDesc{
		ParentID:  req.ParentID,
		ShortName: req.ShortName,
		Name:      req.Name,
		Icon:      req.Icon,
		Page:      req.Page,
		Banner:    req.Banner,
		Desc:      req.Desc,
		Kind:      columnd.ColumnKind(req.Kind),
		Org:       req.Org,
		Owner:     req.Owner,
	}
	if req.ParentID != "" {
		// 校验上级栏目是否存在
		pa, err := c.car.GetColumn(dctx, req.ParentID)
		if err != nil {
			c.ErrServerError(ctx, 2, "查询上级栏目失败", errors.Wrapf(err, "查询上级栏目(%v)失败失败:", req.ParentID))
			return
		}
		if pa == nil {
			c.ErrBadRequest(ctx, 1, "上级栏目不存在")
			return
		}
		// 子栏目和上级栏目的所有者组织保持一致
		desc.Org = pa.Org
		desc.Owner = pa.Owner
	}
	ok, err := c.car.ExistNameByDesc(dctx, "", desc)
	if err != nil {
		c.ErrServerError(ctx, 2, "保存失败", errors.Wrap(err, "检测栏目名称是否存在失败"))
		return
	}
	if ok {
		c.ErrBadRequest(ctx, 3, "栏目名称已经存在")
		return
	}
	id, err := c.car.AddColumn(dctx, desc)
	if err != nil {
		c.ErrServerError(ctx, 2, "保存失败", errors.Wrap(err, "新增栏目失败："))
		return
	}
	c.Success(ctx, map[string]interface{}{"column_id": id})
}

// ReqColumnUpdateDesc 新增栏目请求
type ReqColumnUpdateDesc struct {
	Name      string   `json:"name" binding:"required,max=30"`
	ShortName string   `json:"short_name" binding:"required,max=10"`
	ParentID  string   `json:"parent_id,omitempty" binding:"max=40"`
	Kind      int      `json:"kind"`
	Icon      []string `json:"icon,omitempty"`
	Banner    string   `json:"banner,omitempty"`
	Page      string   `json:"page,omitempty"`
	Desc      string   `json:"desc,omitempty" binding:"max=500"`
	Org       string   `json:"org,omitempty" binding:"max=40"`
}

func (c columnCtrl) updateDesc(ctx *gin.Context) {
	var req ReqColumnUpdateDesc

	if err := ctx.BindJSON(&req); err != nil {
		c.ErrBadRequestByBind(ctx, 1, err)
		return
	}
	columnid := ctx.Param("columnid")
	if columnid == "" {
		c.ErrBadRequest(ctx, 1, "请求参数错误")
		return
	}
	dctx := c.DDDContext(ctx)
	desc := &columnd.ColumnDesc{
		Name:      req.Name,
		Icon:      req.Icon,
		ShortName: req.ShortName,
		Page:      req.Page,
		ParentID:  req.ParentID,
		Banner:    req.Banner,
		Desc:      req.Desc,
		Kind:      columnd.ColumnKind(req.Kind),
		Org:       req.Org,
	}

	ca, err := c.car.GetColumn(dctx, columnid)
	if err != nil {

		c.ErrServerError(ctx, 4, "保存失败", errors.Wrapf(err, "检测栏目(%v)是否存在失败.", columnid))
		return
	}
	if ca == nil {
		c.ErrNotFound(ctx, 5, "栏目不存在", nil)
		return
	}
	ok, err := c.car.ExistNameByDesc(dctx, columnid, *desc)
	if err != nil {

		c.ErrServerError(ctx, 2, "检测栏目名称是否存在失败", errors.Wrapf(err, "检测栏目(%v)名称是否存在失败:", columnid))
		return
	}
	if ok {
		c.ErrBadRequest(ctx, 3, "栏目名称已经存在", nil)
		return
	}
	if desc.ParentID == "" {
		desc.ParentID = ca.ParentID
	}
	err = ca.UpdateDesc(dctx, desc)
	if err != nil {
		c.ErrServerError(ctx, 6, "保存失败", errors.Wrapf(err, "修改栏目(%v)失败.", columnid))
		return
	}
	c.Success(ctx, nil)
}

// ReqColumnUpdateCtrl 新增栏目请求
type ReqColumnUpdateCtrl struct {
	Infourl          string   `json:"infourl"`
	IsColReply       int      `json:"is_col_reply"`
	IsReply          int      `json:"is_reply"`
	IsInfoChk        int      `json:"is_info_chk"`
	IsChk            int      `json:"is_chk"`
	AllowIntCode     []string `json:"allow_int_code"`
	IsSubmit         int      `json:"is_submit"`
	IsPublic         int      `json:"is_public"`
	IsOrg            int      `json:"is_org"`
	InfoMode         int      `json:"info_mode"`
	ProhibitPostInfo int      `json:"prohibit_post_info"` // 禁止发文章 0 不开启 1 开启
}

func (c columnCtrl) updateCtrl(ctx *gin.Context) {
	var req ReqColumnUpdateCtrl

	if err := ctx.BindJSON(&req); err != nil {
		c.ErrBadRequestByBind(ctx, 1, err)
		return
	}
	columnid := ctx.Param("columnid")
	if columnid == "" {
		c.ErrBadRequest(ctx, 1, "请求参数错误")
		return
	}
	dctx := c.DDDContext(ctx)
	ctl := columnd.ColumnCtlParam{
		IsColReply:       req.IsColReply,
		IsReply:          req.IsReply,
		IsChk:            req.IsChk,
		IsInfoChk:        req.IsInfoChk,
		AllowIntCode:     req.AllowIntCode,
		IsSubmit:         req.IsSubmit,
		IsPublic:         req.IsPublic,
		InfoMode:         req.InfoMode,
		Infourl:          req.Infourl,
		IsOrg:            req.IsOrg,
		ProhibitPostInfo: req.ProhibitPostInfo,
	}
	ca, err := c.car.GetColumn(dctx, columnid)
	if err != nil {

		c.ErrServerError(ctx, 4, "保存失败", errors.Wrapf(err, "检测栏目(%v)是否存在失败：", columnid))
		return
	}
	if ca == nil {
		c.ErrNotFound(ctx, 5, "栏目不存在", nil)
		return
	}
	err = ca.UpdateCtlParam(dctx, &ctl)
	if err != nil {
		c.ErrServerError(ctx, 6, "保存失败", errors.Wrapf(err, "修改栏目(%v)控制参数失败：", columnid))
		return
	}
	c.Success(ctx, nil)
}

// // ReqColumnUpdateExtra 新增栏目请求
// type ReqColumnUpdateExtra struct {
// 	ColumnID string      `json:"column_id,omitempty" binding:"required"`
// 	Extras   []ExtraItem `json:"extras,omitempty"`
// }

// ExtraItem 扩展属性
type ExtraItem struct {
	Name        string                 `json:"name" binding:"required,max=30"` //扩展属性名称
	Code        string                 `json:"code" binding:"required,max=20"` //扩展属性编码
	Kind        string                 `json:"kind" binding:"required"`        //扩展属性类型
	Placeholder string                 `json:"placeholder"`                    //扩展属性占位符
	Required    int                    `json:"required"`                       //是否必填 1 是 0 否
	Isupdate    int                    `json:"isupdate"`                       //是否可以被客户端更改1 是 0 否
	Message     string                 `json:"message"`                        //校验消息
	Rules       string                 `json:"rules"`                          //校验规则
	ParamValues map[string]interface{} `json:"param_values"`                   //类型扩展参数
}

func (c columnCtrl) updateExtra(ctx *gin.Context) {
	var req []ExtraItem

	if err := ctx.BindJSON(&req); err != nil {
		c.ErrBadRequestByBind(ctx, 1, err)
		return
	}
	columnid := ctx.Param("columnid")
	if columnid == "" {
		c.ErrBadRequest(ctx, 1, "请求参数错误")
		return
	}
	dctx := c.DDDContext(ctx)
	eis := make([]columnd.ColumnExtraItem, 0, len(req))
	if req != nil {
		for _, v := range req {
			eis = append(eis, columnd.ColumnExtraItem{
				Name:        v.Name,
				Code:        v.Code,
				Kind:        v.Kind,
				Placeholder: v.Placeholder,
				Required:    v.Required,
				Message:     v.Message,
				Rules:       v.Rules,
				ParamValues: v.ParamValues,
				Isupdate:    v.Isupdate,
			})
		}
	}

	ca, err := c.car.GetColumn(dctx, columnid)
	if err != nil {

		c.ErrServerError(ctx, 4, "保存失败", errors.Wrapf(err, "检测栏目(%v)是否存在失败：", columnid))
		return
	}
	if ca == nil {
		c.ErrNotFound(ctx, 5, "栏目不存在", nil)
		return
	}
	err = ca.UpdateExtras(dctx, eis)
	if err != nil {
		c.ErrServerError(ctx, 6, "保存失败", errors.Wrapf(err, "修改栏目(%v)扩展属性失败：", columnid))
		return
	}
	c.Success(ctx, nil)
}

// 获取系统栏目树
func (c columnCtrl) getColumnTreeForSys(ctx *gin.Context) {

	dddctx := ginhook.FromContext(ctx)

	cs, err := c.car.ColumnTreeForSys(dddctx)
	if err != nil {
		c.ErrServerError(ctx, 1, fmt.Sprintf("获取栏目树失败:%v", err), errors.Wrap(err, "获取平台栏目树失败:"))
		return
	}
	if len(cs) == 0 {
		c.Success(ctx, []string{})
		return
	}
	out := c.a2t(cs)
	c.Success(ctx, out)
}

// 获取指定组织栏目树
func (c columnCtrl) getColumnTreeForOrg(ctx *gin.Context) {
	org := ctx.Param("org")
	dddctx := ginhook.FromContext(ctx)
	sys := c.GetIntByQuery(ctx, "sys", 0)
	cs, err := c.car.ColumnTreeForOrg(dddctx, org)
	if err != nil {
		c.ErrServerError(ctx, 1, fmt.Sprintf("获取栏目树失败:%v", err), errors.Wrapf(err, "获取组织（%v）栏目树失败:", org))
		return
	}
	if sys == 1 {
		ss, err := c.car.ColumnSysOrgTree(dddctx)
		if err != nil {
			c.ErrServerError(ctx, 2, fmt.Sprintf("获取系统开放栏目树失败:%v", err), errors.Wrapf(err, "获取组织（%v）栏目树失败:", org))
			return
		}
		cs = append(cs, ss...)
	}
	if len(cs) == 0 {
		c.Success(ctx, []string{})
		return
	}
	out := c.a2t(cs)
	c.Success(ctx, out)
}

// 获取指定用户栏目树
func (c columnCtrl) getColumnTreeForOwner(ctx *gin.Context) {
	owner := ctx.Param("owner")
	dddctx := ginhook.FromContext(ctx)

	cs, err := c.car.ColumnTreeForOwner(dddctx, owner)
	if err != nil {
		c.ErrServerError(ctx, 1, fmt.Sprintf("获取栏目树失败:%v", err), errors.Wrapf(err, "获取用户（%v）栏目树失败:", owner))
		return
	}
	if len(cs) == 0 {
		c.Success(ctx, []string{})
		return
	}
	out := c.a2t(cs)
	c.Success(ctx, out)
}

// 获取登录用自己的栏目树
func (c columnCtrl) getColumnTreeForSelf(ctx *gin.Context) {

	dddctx := ginhook.FromContext(ctx)
	uid := dddctx.UID()
	if uid == "" {
		c.ErrUnauthorized(ctx, "找不到登录用户", nil)
		return
	}
	cs, err := c.car.ColumnTreeForOwner(dddctx, uid)
	if err != nil {
		c.ErrServerError(ctx, 1, "获取栏目树失败。", errors.Wrapf(err, "获取用户（%v）自己的栏目树失败:", uid))
		return
	}
	if len(cs) == 0 {
		c.Success(ctx, []string{})
		return
	}
	out := c.a2t(cs)
	c.Success(ctx, out)
}

// 获取登录用自己的栏目树
func (c columnCtrl) getColumnChildren(ctx *gin.Context) {

	columnid := ctx.Param("columnid")
	dctx := c.DDDContext(ctx)
	if columnid == "" {
		c.ErrBadRequest(ctx, 1, "请求参数错误", nil)
		return
	}
	ca, err := c.car.GetColumn(dctx, columnid)
	if err != nil {
		c.ErrServerError(ctx, 2, "查找栏目失败", errors.Wrapf(err, "检测栏目(%v)是否存在失败：", columnid))
		return
	}
	if ca == nil {
		c.ErrNotFound(ctx, 3, "栏目不存在", nil)
		return
	}
	cs, err := ca.Children(dctx)
	if err != nil {
		c.ErrServerError(ctx, 4, "获取子栏目失败。", errors.Wrapf(err, "获取栏目（%v）的子栏目失败:", columnid))
		return
	}

	c.Success(ctx, cs)
}

// 树的转换
func (c columnCtrl) a2t(cs []columnd.ColumnAggregate) []*SelectTreeNode {
	cachemap := make(map[string]*SelectTreeNode)
	trmap := make(map[string]*[]*SelectTreeNode)

	for _, v := range cs {
		t, ok := trmap[v.ParentID]
		if !ok {
			tmp := make([]*SelectTreeNode, 0)
			t = &tmp
			trmap[v.ParentID] = t
		}
		n := &SelectTreeNode{
			Key:    v.ColumnID,
			Title:  v.Name,
			Value:  v.ColumnID,
			Parent: v.ParentID,
		}
		*t = append(*t, n)
		cachemap[v.ColumnID] = n
	}
	for _, v := range cachemap {
		if t, ok := trmap[v.Key]; ok {
			v.Children = *t
		}
	}
	return *trmap[""]
}

func (c columnCtrl) delete(ctx *gin.Context) {
	columnid := ctx.Param("columnid")
	dctx := c.DDDContext(ctx)
	if columnid == "" {
		c.ErrBadRequest(ctx, 1, "请求参数错误", nil)
		return
	}
	ca, err := c.car.GetColumn(dctx, columnid)
	if err != nil {
		c.ErrServerError(ctx, 2, "删除失败", errors.Wrapf(err, "检测栏目(%v)是否存在失败：", columnid))
		return
	}
	if ca == nil {
		c.ErrNotFound(ctx, 3, "栏目不存在", nil)
		return
	}
	if ca.InfoNum > 0 {
		c.ErrBadRequest(ctx, 4, "栏目下存在信息内容，不能删除", nil)
		return
	}
	if ok, err := ca.ExistChildren(dctx); err != nil {
		c.ErrServerError(ctx, 5, "查询栏目下是否存在子栏目失败", err)
		return
	} else if ok {
		c.ErrBadRequest(ctx, 6, "查询栏目下存在子栏目不能删除", err)
		return
	}
	err = ca.Delete(dctx)
	if err != nil {
		c.ErrServerError(ctx, 7, "删除失败", errors.Wrapf(err, "删除栏目(%v)失败：", columnid))
		return
	}
	c.Success(ctx, nil)
}
func (c columnCtrl) lock(ctx *gin.Context) {
	columnid := ctx.Param("columnid")
	dctx := c.DDDContext(ctx)
	if columnid == "" {
		c.ErrBadRequest(ctx, 1, "请求参数错误", nil)
		return
	}
	ca, err := c.car.GetColumn(dctx, columnid)
	if err != nil {
		c.ErrServerError(ctx, 2, "锁定失败", errors.Wrapf(err, "检测栏目(%v)是否存在失败：", columnid))
		return
	}
	if ca == nil {
		c.ErrNotFound(ctx, 3, "栏目不存在", nil)
		return
	}

	err = ca.LockColumn(dctx)
	if err != nil {
		c.ErrServerError(ctx, 7, fmt.Sprintf("锁定失败:%v", err.Error()), errors.Wrapf(err, "删除栏目(%v)失败：", columnid))
		return
	}
	c.Success(ctx, nil)
}
func (c columnCtrl) unlock(ctx *gin.Context) {
	columnid := ctx.Param("columnid")
	dctx := c.DDDContext(ctx)
	if columnid == "" {
		c.ErrBadRequest(ctx, 1, "请求参数错误", nil)
		return
	}
	ca, err := c.car.GetColumn(dctx, columnid)
	if err != nil {
		c.ErrServerError(ctx, 2, "解锁失败", errors.Wrapf(err, "检测栏目(%v)是否存在失败：", columnid))
		return
	}
	if ca == nil {
		c.ErrNotFound(ctx, 3, "栏目不存在", nil)
		return
	}

	err = ca.UnLockColumn(dctx)
	if err != nil {
		c.ErrServerError(ctx, 7, fmt.Sprintf("解锁失败:%v", err.Error()), errors.Wrapf(err, "删除栏目(%v)失败：", columnid))
		return
	}
	c.Success(ctx, nil)
}

func (c columnCtrl) destroy(ctx *gin.Context) {
	columnid := ctx.Param("columnid")
	dctx := c.DDDContext(ctx)
	if columnid == "" {
		c.ErrBadRequest(ctx, 1, "请求参数错误", nil)
		return
	}
	ca, err := c.car.GetColumn(dctx, columnid)
	if err != nil {
		c.ErrServerError(ctx, 2, "删除失败", errors.Wrapf(err, "检测栏目(%v)是否存在失败：", columnid))
		return
	}
	if ca == nil {
		c.ErrNotFound(ctx, 3, "栏目不存在", nil)
		return
	}
	if ca.InfoNum > 0 {
		c.ErrBadRequest(ctx, 4, "栏目下存在信息内容，不能删除", nil)
		return
	}
	if ca.Status != -1 {
		c.ErrBadRequest(ctx, 5, "只有已经删除的栏目才能被彻底删除", nil)
		return
	}
	err = ca.Destroy(dctx)
	if err != nil {
		c.ErrServerError(ctx, 6, "彻底删除失败", errors.Wrapf(err, "删除栏目(%v)失败：", columnid))
		return
	}
	c.Success(ctx, nil)
}

func (c columnCtrl) recover(ctx *gin.Context) {
	columnid := ctx.Param("columnid")
	dctx := c.DDDContext(ctx)
	if columnid == "" {
		c.ErrBadRequest(ctx, 1, "请求参数错误", nil)
		return
	}
	ca, err := c.car.GetColumn(dctx, columnid)
	if err != nil {
		c.ErrServerError(ctx, 2, "恢复失败", errors.Wrapf(err, "检测栏目(%v)是否存在失败：", columnid))
		return
	}
	if ca == nil {
		c.ErrNotFound(ctx, 3, "栏目不存在", nil)
		return
	}
	if ca.Status != -1 {
		c.ErrBadRequest(ctx, 5, "只有已经删除的栏目才能被恢复", nil)
		return
	}
	err = ca.Recover(dctx)
	if err != nil {
		c.ErrServerError(ctx, 6, "恢复失败", errors.Wrapf(err, "删除栏目(%v)失败：", columnid))
		return
	}
	c.Success(ctx, nil)
}

// 获取栏目信息
func (c columnCtrl) getColumn(ctx *gin.Context) {

	columnid := ctx.Param("columnid")
	dctx := c.DDDContext(ctx)
	if columnid == "" {
		c.ErrBadRequest(ctx, 1, "请求参数错误", nil)
		return
	}
	ca, err := c.car.GetColumn(dctx, columnid)
	if err != nil {
		c.ErrServerError(ctx, 2, "查找栏目失败", errors.Wrapf(err, "检测栏目(%v)是否存在失败：%v", columnid, err))
		return
	}
	if ca == nil {
		c.ErrNotFound(ctx, 3, "栏目不存在", nil)
		return
	}
	c.Success(ctx, ca)
}

// 获取栏目描述信息
func (c columnCtrl) getColumnDesc(ctx *gin.Context) {

	columnid := ctx.Param("columnid")
	dctx := c.DDDContext(ctx)
	if columnid == "" {
		c.ErrBadRequest(ctx, 1, "请求参数错误", nil)
		return
	}
	ca, err := c.car.GetColumn(dctx, columnid)
	if err != nil {
		c.ErrServerError(ctx, 2, "查找栏目失败", errors.Wrapf(err, "检测栏目(%v)是否存在失败：", columnid))
		return
	}
	if ca == nil {
		c.ErrNotFound(ctx, 3, "栏目不存在", nil)
		return
	}

	c.Success(ctx, ca.ColumnDesc)
}

// 获取栏目控制参数
func (c columnCtrl) getColumnCtrl(ctx *gin.Context) {

	columnid := ctx.Param("columnid")
	dctx := c.DDDContext(ctx)
	if columnid == "" {
		c.ErrBadRequest(ctx, 1, "请求参数错误", nil)
		return
	}
	ca, err := c.car.GetColumn(dctx, columnid)
	if err != nil {
		c.ErrServerError(ctx, 2, "查找栏目失败", errors.Wrapf(err, "检测栏目(%v)是否存在失败：", columnid))
		return
	}
	if ca == nil {
		c.ErrNotFound(ctx, 3, "栏目不存在", nil)
		return
	}

	c.Success(ctx, ca.ColumnCtlParam)
}

// 获取栏目扩展属性
func (c columnCtrl) getColumnExtra(ctx *gin.Context) {

	columnid := ctx.Param("columnid")
	dctx := c.DDDContext(ctx)
	if columnid == "" {
		c.ErrBadRequest(ctx, 1, "请求参数错误", nil)
		return
	}
	ca, err := c.car.GetColumn(dctx, columnid)
	if err != nil {
		c.ErrServerError(ctx, 2, "查找栏目失败", errors.Wrapf(err, "检测栏目(%v)是否存在失败：", columnid))
		return
	}
	if ca == nil {
		c.ErrNotFound(ctx, 3, "栏目不存在", nil)
		return
	}
	if ca.Extras == nil {
		ca.Extras = make([]columnd.ColumnExtraItem, 0)
	}
	c.Success(ctx, ca.Extras)
}

// 获取query中的栏目查询参数
func (c columnCtrl) getColumnSearch(ctx *gin.Context) columnd.ColumnSearch {
	return columnd.ColumnSearch{
		Key:    ctx.DefaultQuery("key", ""),
		PID:    ctx.DefaultQuery("pid", ""),
		Owner:  ctx.DefaultQuery("owner", ""),
		Org:    ctx.DefaultQuery("org", ""),
		Range:  c.GetIntByQuery(ctx, "range", 0),
		Status: c.GetIntArrayByQuery(ctx, "status", []int{0, 1}),
	}
}

// 分页获取栏目列表
func (c columnCtrl) getColumnPageList(ctx *gin.Context) {

	page := c.GetPageInfo(ctx, common.PageModeNum)
	dctx := c.DDDContext(ctx)
	sch := c.getColumnSearch(ctx)
	pr, cs, err := c.car.QueryPage(dctx, sch, page)
	if err != nil {
		c.ErrServerError(ctx, 1, "查找栏目失败", errors.Wrap(err, "查找栏目失败."))
		return
	}
	if len(cs) == 0 {
		cs = make([]columnd.ColumnAggregate, 0)
	}
	c.SuccessPage(ctx, page, pr, cs)
}

// 分页获取栏目列表
func (c columnCtrl) getExtraTypeAll(ctx *gin.Context) {
	dctx := c.DDDContext(ctx)
	es, err := c.column.ExtraTypeAggregteRoot().LoadAll(dctx)
	if err != nil {
		c.ErrServerError(ctx, 1, "查找栏目扩展扩展属性类型失败", err)
		return
	}
	if es == nil {
		es = make([]columnd.ExtraType, 0)
	}
	c.Success(ctx, es)
}

// 分页获取栏目列表
func (c columnCtrl) getExtraTypeOne(ctx *gin.Context) {
	code := ctx.Param("code")
	if code == "" {
		c.ErrBadRequest(ctx, 1, "参数错误", nil)
		return
	}
	dctx := c.DDDContext(ctx)
	es, err := c.column.ExtraTypeAggregteRoot().LoadOne(dctx, code)
	if err != nil {
		c.ErrServerError(ctx, 2, "查找栏目扩展扩展属性类型失败", err)
		return
	}
	c.Success(ctx, es)
}
